package com.woniuxy.cloud.util;

import com.woniuxy.cloud.exception.ActiveCodeException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

import java.util.List;


/**
 * 参数异常处理
 *
 * @author 周川雄
 * @date 2022/1/3 20:38
 */
public class ValidatedUtil {

    public static void ValidatedException(BindingResult result) {
        if (result.hasErrors()) {
            List<ObjectError> allErrors = result.getAllErrors();
            allErrors.forEach(error -> {
                System.out.println(error.getDefaultMessage());
            });

            throw new ActiveCodeException(result.getFieldError().getDefaultMessage(), 10099);
        }
    }
}
